home *** CD-ROM | disk | FTP | other *** search
/ Aminet 52 / Aminet 52 (2002)(GTI - Schatztruhe)[!][Dec 2002].iso / Aminet / util / moni / Scout-src.lha / source / objects / scout_screenmode.c < prev    next >
Encoding:
C/C++ Source or Header  |  2002-09-17  |  15.2 KB  |  400 lines

  1. /**
  2.  * Scout - The Amiga System Monitor
  3.  *
  4.  *------------------------------------------------------------------
  5.  *
  6.  * This program is free software; you can redistribute it and/or modify
  7.  * it under the terms of the GNU General Public License as published by
  8.  * the Free Software Foundation; either version 2 of the License, or
  9.  * any later version.
  10.  *
  11.  * This program is distributed in the hope that it will be useful,
  12.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14.  * GNU General Public License for more details.
  15.  *
  16.  * You should have received a copy of the GNU General Public License
  17.  * along with this program; if not, write to the Free Software
  18.  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  19.  *
  20.  * You must not use this source code to gain profit of any kind!
  21.  *
  22.  *------------------------------------------------------------------
  23.  *
  24.  * @author Andreas Gelhausen
  25.  * @author Richard Körber <rkoerber@gmx.de>
  26.  */
  27.  
  28. #include "system_headers.h"
  29.  
  30. struct ScreenModesCallbackUserData {
  31.     APTR ud_List;
  32.     ULONG ud_Count;
  33. };
  34.  
  35. static __asm __saveds LONG smodelist_con2func(register __a2 Object *obj, register __a1 struct NList_ConstructMessage *msg, register __a0 struct Hook *hook)
  36. {
  37.     return AllocListEntry(msg->pool, msg->entry, sizeof(struct ScreenModeEntry));
  38. }
  39.  
  40. MakeHook(smodelist_con2hook, smodelist_con2func);
  41.  
  42. static __asm __saveds LONG smodelist_des2func(register __a2 Object *obj, register __a1 struct NList_DestructMessage *msg, register __a0 struct Hook *hook)
  43. {
  44.     FreeListEntry(msg->pool, &msg->entry);
  45.  
  46.     return 0;
  47. }
  48.  
  49. MakeHook(smodelist_des2hook, smodelist_des2func);
  50.  
  51. static __asm __saveds LONG smodelist_dsp2func(register __a2 Object *obj, register __a1 struct NList_DisplayMessage *msg, register __a0 struct Hook *hook)
  52. {
  53.     struct ScreenModeEntry *sme = (struct ScreenModeEntry *)msg->entry;
  54.  
  55.     if (sme) {
  56.         msg->strings[0] = sme->sme_Id;
  57.         msg->strings[1] = sme->sme_Name;
  58.         msg->strings[2] = sme->sme_Width;
  59.         msg->strings[3] = sme->sme_Height;
  60.         msg->strings[4] = sme->sme_Depth;
  61.     } else {
  62.         msg->strings[0] = "ModeID";
  63.         msg->strings[1] = "Name";
  64.         msg->strings[2] = "Width";
  65.         msg->strings[3] = "Height";
  66.         msg->strings[4] = "Depth";
  67.         msg->preparses[0] = MUIX_B;
  68.         msg->preparses[1] = MUIX_B;
  69.         msg->preparses[2] = MUIX_B;
  70.         msg->preparses[3] = MUIX_B;
  71.         msg->preparses[4] = MUIX_B;
  72.     }
  73.  
  74.     return 0;
  75. }
  76.  
  77. MakeHook(smodelist_dsp2hook, smodelist_dsp2func);
  78.  
  79. static LONG smodelist_cmp2colfunc( struct ScreenModeEntry *sme1,
  80.                                 struct ScreenModeEntry *sme2,
  81.                                 ULONG column )
  82. {
  83.     switch (column) {
  84.         case 0: return stricmp(sme1->sme_Id, sme2->sme_Id);
  85.         case 1: return stricmp(sme1->sme_Name, sme2->sme_Name);
  86.         case 2: return stricmp(sme1->sme_Width, sme2->sme_Width);
  87.         case 3: return stricmp(sme1->sme_Height, sme2->sme_Height);
  88.         case 4: return stricmp(sme1->sme_Depth, sme2->sme_Depth);
  89.     }
  90. }
  91.  
  92. static __asm __saveds LONG smodelist_cmp2func(register __a2 Object *obj, register __a1 struct NList_CompareMessage *msg, register __a0 struct Hook *hook)
  93. {
  94.     LONG cmp;
  95.     struct ScreenModeEntry *sme1, *sme2;
  96.     ULONG col1, col2;
  97.  
  98.     sme1 = (struct ScreenModeEntry *)msg->entry1;
  99.     sme2 = (struct ScreenModeEntry *)msg->entry2;
  100.     col1 = msg->sort_type & MUIV_NList_TitleMark_ColMask;
  101.     col2 = msg->sort_type2 & MUIV_NList_TitleMark2_ColMask;
  102.  
  103.     if (msg->sort_type == MUIV_NList_SortType_None) return 0;
  104.  
  105.     if (msg->sort_type & MUIV_NList_TitleMark_TypeMask) {
  106.         cmp = smodelist_cmp2colfunc(sme2, sme1, col1);
  107.     } else {
  108.         cmp = smodelist_cmp2colfunc(sme1, sme2, col1);
  109.     }
  110.  
  111.     if (cmp != 0 || col1 == col2) return cmp;
  112.  
  113.     if (msg->sort_type2 & MUIV_NList_TitleMark2_TypeMask) {
  114.         cmp = smodelist_cmp2colfunc(sme2, sme1, col2);
  115.     } else {
  116.         cmp = smodelist_cmp2colfunc(sme1, sme2, col2);
  117.     }
  118.  
  119.     return cmp;
  120. }
  121.  
  122. MakeHook(smodelist_cmp2hook, smodelist_cmp2func);
  123.  
  124. static void ReceiveList( void (* callback)( struct ScreenModeEntry *sme, void *userData ),
  125.                          void *userData )
  126. {
  127.     struct ScreenModeEntry *sme;
  128.  
  129.     if (sme = tbAllocVecPooled(globalPool, sizeof(struct ScreenModeEntry))) {
  130.         if (SendDaemon("GetSModeList")) {
  131.             while (ReceiveDecodedEntry((UBYTE *)sme, sizeof(struct ScreenModeEntry))) {
  132.                 callback(sme, userData);
  133.             }
  134.         }
  135.  
  136.         tbFreeVecPooled(globalPool, sme);
  137.     }
  138. }
  139.  
  140. static void IterateList( void (* callback)( struct ScreenModeEntry *sme, void *userData ),
  141.                          void *userData )
  142. {
  143.     struct ScreenModeEntry *sme;
  144.  
  145.     if (sme = tbAllocVecPooled(globalPool, sizeof(struct ScreenModeEntry))) {
  146.         ULONG id = INVALID_ID;
  147.  
  148.         while ((id = NextDisplayInfo(id)) != INVALID_ID) {
  149.             struct NameInfo idname;
  150.             struct DimensionInfo iddim;
  151.  
  152.             sme->sme_ModeID = id;
  153.             _snprintf(sme->sme_Id, sizeof(sme->sme_Id), "$%08lx", id);
  154.  
  155.             GetDisplayInfoData(NULL, (UBYTE *)&iddim, sizeof(struct DimensionInfo), DTAG_DIMS, id);
  156.             _snprintf(sme->sme_Width, sizeof(sme->sme_Width), "%5ld", iddim.Nominal.MaxX-iddim.Nominal.MinX + 1);
  157.             _snprintf(sme->sme_Height, sizeof(sme->sme_Height), "%5ld", iddim.Nominal.MaxY-iddim.Nominal.MinY + 1);
  158.             _snprintf(sme->sme_Depth, sizeof(sme->sme_Depth), "%5ld", (iddim.MaxDepth == 32) ? 24 : iddim.MaxDepth);
  159.  
  160.             if (GetDisplayInfoData(NULL, (UBYTE *)&idname, sizeof(struct NameInfo), DTAG_NAME, id)) {
  161.                 stccpy(sme->sme_Name, idname.Name, sizeof(sme->sme_Name));
  162.             } else {
  163.                 struct MonitorInfo idmon;
  164.                 struct DisplayInfo iddisp;
  165.  
  166.                 if (GetDisplayInfoData(NULL, (UBYTE *)&idmon, sizeof(struct MonitorInfo), DTAG_MNTR, id)) {
  167.                     if (GetDisplayInfoData(NULL, (UBYTE *)&iddisp, sizeof(struct DisplayInfo), DTAG_DISP, id)) {
  168.                         ULONG prop = iddisp.PropertyFlags;
  169.                         WORD  xres = iddim.Nominal.MaxX - iddim.Nominal.MinX;
  170.  
  171.                         NameCopy(sme->sme_Name, idmon.Mspc->ms_Node.xln_Name);
  172.                         if (sme->sme_Name[0] == 'E') {
  173.                             if (!strcmp(sme->sme_Name, "EURO72:")) stccpy(sme->sme_Name, "EURO:72Hz ", sizeof(sme->sme_Name));
  174.                             if (!strcmp(sme->sme_Name, "EURO36:")) stccpy(sme->sme_Name, "EURO:36Hz ", sizeof(sme->sme_Name));
  175.                         }
  176.  
  177.                         if (xres > 1200)     _strcatn(sme->sme_Name, "SuperHighRes", sizeof(sme->sme_Name));
  178.                         else if (xres > 600) _strcatn(sme->sme_Name, "HighRes", sizeof(sme->sme_Name));
  179.                         else if (xres > 300) _strcatn(sme->sme_Name, "LowRes", sizeof(sme->sme_Name));
  180.                         else                 _strcatn(sme->sme_Name, "ExtraLowRes", sizeof(sme->sme_Name));
  181.  
  182.                         if (prop & DIPF_IS_DUALPF        ) {
  183.                             _strcatn(sme->sme_Name," DualPF", sizeof(sme->sme_Name));
  184.                             if (prop & DIPF_IS_PF2PRI) _strcatn(sme->sme_Name, "2", sizeof(sme->sme_Name));
  185.                         }
  186.                         if (prop & DIPF_IS_HAM           ) _strcatn(sme->sme_Name, " HAM", sizeof(sme->sme_Name));
  187.                         if (prop & DIPF_IS_EXTRAHALFBRITE) _strcatn(sme->sme_Name, " EHB", sizeof(sme->sme_Name));
  188.                         if (prop & DIPF_IS_LACE          ) _strcatn(sme->sme_Name, " Interlace", sizeof(sme->sme_Name));
  189.                         if (prop & DIPF_IS_SCANDBL       ) _strcatn(sme->sme_Name, " DblScan", sizeof(sme->sme_Name));
  190.                     } else {
  191.                         stccpy(sme->sme_Name, idmon.Mspc->ms_Node.xln_Name, sizeof(sme->sme_Name));
  192.                     }
  193.                 } else {
  194.                     stccpy(sme->sme_Name, "< ??? >", sizeof(sme->sme_Name));
  195.                 }
  196.             }
  197.  
  198.             callback(sme, userData);
  199.         }
  200.  
  201.         tbFreeVecPooled(globalPool, sme);
  202.     }
  203. }
  204.  
  205. static void UpdateCallback( struct ScreenModeEntry *sme,
  206.                             void *userData )
  207. {
  208.     struct ScreenModesCallbackUserData *ud = (struct ScreenModesCallbackUserData *)userData;
  209.  
  210.     InsertSortedEntry(ud->ud_List, sme);
  211.     ud->ud_Count++;
  212. }
  213.  
  214. static void PrintCallback( struct ScreenModeEntry *sme,
  215.                            void *userData )
  216. {
  217.     PrintFOneLine((BPTR)userData, " %s %5s %5s %2s  %s\n", sme->sme_Id, sme->sme_Width, sme->sme_Height, sme->sme_Depth, sme->sme_Name);
  218. }
  219.  
  220. static void SendCallback( struct ScreenModeEntry *sme,
  221.                           void *userData )
  222. {
  223.     SendEncodedEntry((UBYTE *)sme, sizeof(struct ScreenModeEntry));
  224. }
  225.  
  226. static ULONG __saveds mNew( struct IClass *cl,
  227.                             Object *obj,
  228.                             struct opSet *msg )
  229. {
  230.     APTR smodelist, smodetext, smodecount, updateButton, printButton, moreButton, exitButton;
  231.  
  232.     if (obj = (Object *)DoSuperNew(cl, obj,
  233.         MUIA_HelpNode, ScreenModeText,
  234.         MUIA_Window_ID, MakeID('S','M','D','E'),
  235.         WindowContents, VGroup,
  236.  
  237.             Child, smodelist = MyNListviewObject(MakeID('S','M','L','V'), "BAR,BAR,BAR,BAR,BAR", &smodelist_con2hook, &smodelist_des2hook, &smodelist_dsp2hook, &smodelist_cmp2hook, TRUE),
  238.             Child, MyBelowListview(&smodetext, &smodecount),
  239.  
  240.             Child, MyVSpace(4),
  241.  
  242.             Child, HGroup, MUIA_Group_SameSize, TRUE,
  243.                 Child, updateButton = MakeButton(txtUpdate),
  244.                 Child, printButton  = MakeButton(txtPrint),
  245.                 Child, moreButton   = MakeButton(txtMore),
  246.                 Child, exitButton   = MakeButton(txtExit),
  247.             End,
  248.         End,
  249.         TAG_MORE, msg->ops_AttrList))
  250.     {
  251.         struct ScreenModesWinData *smwd = INST_DATA(cl, obj);
  252.         APTR parent;
  253.  
  254.         smwd->smwd_ScreenModeList = smodelist;
  255.         smwd->smwd_ScreenModeText = smodetext;
  256.         smwd->smwd_ScreenModeCount = smodecount;
  257.         smwd->smwd_MoreButton = moreButton;
  258.  
  259.         parent = (APTR)GetTagData(MUIA_Window_ParentWindow, (ULONG)NULL, msg->ops_AttrList);
  260.  
  261.         set(obj, MUIA_Window_Title, MyGetWindowTitle("SCREENMODES", smwd->smwd_Title, sizeof(smwd->smwd_Title)));
  262.         set(obj, MUIA_Window_ActiveObject, smodelist);
  263.         set(moreButton, MUIA_Disabled, TRUE);
  264.  
  265.         DoMethod(parent,       MUIM_Window_AddChildWindow, obj);
  266.         DoMethod(obj,          MUIM_Notify, MUIA_Window_CloseRequest, TRUE,           MUIV_Notify_Application, 5, MUIM_Application_PushMethod, parent, 2, MUIM_Window_RemChildWindow, obj);
  267.         DoMethod(smodelist,    MUIM_Notify, MUIA_NList_Active,        MUIV_EveryTime, obj,                     1, MUIM_ScreenModesWin_ListChange);
  268.         DoMethod(smodelist,    MUIM_Notify, MUIA_NList_DoubleClick,   MUIV_EveryTime, obj,                     1, MUIM_ScreenModesWin_More);
  269.         DoMethod(updateButton, MUIM_Notify, MUIA_Pressed,             FALSE,          obj,                     1, MUIM_ScreenModesWin_Update);
  270.         DoMethod(printButton,  MUIM_Notify, MUIA_Pressed,             FALSE,          obj,                     1, MUIM_ScreenModesWin_Print);
  271.         DoMethod(moreButton,   MUIM_Notify, MUIA_Pressed,             FALSE,          obj,                     1, MUIM_ScreenModesWin_More);
  272.         DoMethod(exitButton,   MUIM_Notify, MUIA_Pressed,             FALSE,          obj,                     3, MUIM_Set, MUIA_Window_CloseRequest, TRUE);
  273.         DoMethod(smodelist,    MUIM_NList_Sort3, MUIV_NList_Sort3_SortType_1, MUIV_NList_SortTypeAdd_None, MUIV_NList_Sort3_SortType_Both);
  274.     }
  275.  
  276.     return (ULONG)obj;
  277. }
  278.  
  279. static ULONG __saveds mDispose( struct IClass *cl,
  280.                                 Object *obj,
  281.                                 struct opSet *msg )
  282. {
  283.     struct ScreenModesWinData *smwd = INST_DATA(cl, obj);
  284.  
  285.     set(obj, MUIA_Window_Open, FALSE);
  286.     DoMethod(smwd->smwd_ScreenModeList, MUIM_NList_Clear);
  287.  
  288.     return (DoSuperMethodA(cl, obj, msg));
  289. }
  290.  
  291. static ULONG __saveds mUpdate( struct IClass *cl,
  292.                                Object *obj,
  293.                                Msg msg )
  294. {
  295.     struct ScreenModesWinData *smwd = INST_DATA(cl, obj);
  296.     struct ScreenModesCallbackUserData ud;
  297.  
  298.     ApplicationSleep(TRUE);
  299.     set(smwd->smwd_ScreenModeList, MUIA_NList_Quiet, TRUE);
  300.     DoMethod(smwd->smwd_ScreenModeList, MUIM_NList_Clear);
  301.  
  302.     ud.ud_List = smwd->smwd_ScreenModeList;
  303.     ud.ud_Count = 0;
  304.  
  305.     if (clientstate) {
  306.         ReceiveList(UpdateCallback, &ud);
  307.     } else {
  308.         IterateList(UpdateCallback, &ud);
  309.     }
  310.  
  311.     SetCountText(smwd->smwd_ScreenModeCount, ud.ud_Count);
  312.     MySetContents(smwd->smwd_ScreenModeText, "");
  313.  
  314.     set(smwd->smwd_ScreenModeList, MUIA_NList_Quiet, FALSE);
  315.     set(smwd->smwd_MoreButton, MUIA_Disabled, TRUE);
  316.     ApplicationSleep(FALSE);
  317.  
  318.     return 0;
  319. }
  320.  
  321. static ULONG __saveds mPrint( struct IClass *cl,
  322.                               Object *obj,
  323.                               Msg msg )
  324. {
  325.     PrintSMode(NULL);
  326.  
  327.     return 0;
  328. }
  329.  
  330. static ULONG __saveds mMore( struct IClass *cl,
  331.                              Object *obj,
  332.                              Msg msg )
  333. {
  334.     struct ScreenModesWinData *smwd = INST_DATA(cl, obj);
  335.     struct ScreenModeEntry *sme;
  336.  
  337.     if (sme = (struct ScreenModeEntry *)GetActiveEntry(smwd->smwd_ScreenModeList)) {
  338.         APTR detailWin;
  339.  
  340.         if (detailWin = ScreenModesDetailWindowObject,
  341.                 MUIA_Window_ParentWindow, obj,
  342.                 MUIA_Window_MaxChildWindowCount, (opts.SingleWindows) ? 1 : 0,
  343.             End) {
  344.             set(detailWin, MUIA_ScreenModesDetailWin_ScreenMode, sme);
  345.             set(detailWin, MUIA_Window_Open, TRUE);
  346.         }
  347.     }
  348.  
  349.     return 0;
  350. }
  351.  
  352. static ULONG __saveds mListChange( struct IClass *cl,
  353.                                    Object *obj,
  354.                                    Msg msg )
  355. {
  356.     struct ScreenModesWinData *smwd = INST_DATA(cl, obj);
  357.     struct ScreenModeEntry *sme;
  358.  
  359.     if (sme = (struct ScreenModeEntry *)GetActiveEntry(smwd->smwd_ScreenModeList)) {
  360.         MySetContents(smwd->smwd_ScreenModeText, "%s \"%s\"", sme->sme_Id, sme->sme_Name);
  361.         if (!clientstate) set(smwd->smwd_MoreButton, MUIA_Disabled, FALSE);
  362.     }
  363.  
  364.     return 0;
  365. }
  366.  
  367. ULONG __asm __saveds ScreenModesWinDispatcher( register __a0 struct IClass *cl,
  368.                                                register __a2 Object *obj,
  369.                                                register __a1 Msg msg )
  370. {
  371.     switch (msg->MethodID) {
  372.         case OM_NEW:                         return (mNew(cl, obj, (APTR)msg));
  373.         case OM_DISPOSE:                     return (mDispose(cl, obj, (APTR)msg));
  374.         case MUIM_ScreenModesWin_Update:     return (mUpdate(cl, obj, (APTR)msg));
  375.         case MUIM_ScreenModesWin_Print:      return (mPrint(cl, obj, (APTR)msg));
  376.         case MUIM_ScreenModesWin_More:       return (mMore(cl, obj, (APTR)msg));
  377.         case MUIM_ScreenModesWin_ListChange: return (mListChange(cl, obj, (APTR)msg));
  378.     }
  379.  
  380.     return (DoSuperMethodA(cl, obj, msg));
  381. }
  382.  
  383. void PrintSMode( char *filename )
  384. {
  385.     BPTR handle;
  386.  
  387.     if (handle = HandlePrintStart(filename)) {
  388.         PrintFOneLine(handle, "\n  ModeID    Wdth  Hght  Dpth  ScreenMode\n\n");
  389.         IterateList(PrintCallback, (void *)handle);
  390.     }
  391.  
  392.     HandlePrintStop();
  393. }
  394.  
  395. void SendSModeList( void )
  396. {
  397.     IterateList(SendCallback, NULL);
  398. }
  399.  
  400.